package org.redmaple.core.retrieving.type;

import java.util.Arrays;
import java.util.List;

import org.redmaple.core.support.ReadmapleCoreConstant.RequestParamterInfo;

/**
 * @author Xiangyun
 *
 */
public class INType implements Type {

	private static final String SYMBOL = "IN";

	@Override
	public Object transform(Object obj) {
		if (obj == null) {
			throw new TypeValueException(SYMBOL + "类型的值不能为空");
		}
		if (obj instanceof List) {
			return obj;
		} else if (obj.getClass().isArray()) {
			List<Object> ret = Arrays.asList(obj);
			return ret;
		} else if (obj instanceof String) {
			List<String> ret = Arrays.asList(((String) obj)
					.split(RequestParamterInfo.REQUEST_DEFAULT_DATA_SEPARATOR));
			return ret;
		} else {
			throw new TypeValueException(obj.getClass().getName() + "无法在"
					+ SYMBOL + "类型使用");
		}
	}

	@Override
	public String getSymbol() {
		return SYMBOL;
	}

}
